'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');

module.exports = Generator.extend({
  prompting: function () {
    // Have Yeoman greet the user.
    this.log(chalk.green(
      '🍺 Welcome to the generator-webpack-babel!'
    ));

    const prompts = [{
      type: 'confirm',
      name: 'someAnswer',
      message: 'Are you ready?',
      default: true
    }];

    return this.prompt(prompts).then(function (props) {
      // To access props later use this.props.someAnswer;
      this.props = props;
    }.bind(this));
  },

  writing: function () {
    this.fs.copy(
      this.templatePath('*'),
      this.destinationRoot(),
      {globOptions: {dot: true}}
    );
    this.fs.copy(
      this.templatePath('src'),
      this.destinationPath('src')
    );
    this.fs.copy(
      this.templatePath('build'),
      this.destinationPath('build')
    );
    this.fs.copy(
      this.templatePath('src/assets/images/yeoman-logo.png'),
      this.destinationPath('src/assets/images/yeoman-logo.png')
    );
    this.fs.delete(
      this.destinationPath('.npmignore')
    );
    this.fs.write(
      this.destinationPath('.gitignore'),
      `
      dist

      # Created by https://www.gitignore.io/api/node

      ### Node ###
      # Logs
      logs
      *.log
      npm-debug.log*
      yarn-debug.log*
      yarn-error.log*

      # Runtime data
      pids
      *.pid
      *.seed
      *.pid.lock

      # Directory for instrumented libs generated by jscoverage/JSCover
      lib-cov

      # Coverage directory used by tools like istanbul
      coverage

      # nyc test coverage
      .nyc_output

      # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
      .grunt

      # Bower dependency directory (https://bower.io/)
      bower_components

      # node-waf configuration
      .lock-wscript

      # Compiled binary addons (http://nodejs.org/api/addons.html)
      build/Release

      # Dependency directories
      node_modules/
      jspm_packages/

      # Typescript v1 declaration files
      typings/

      # Optional npm cache directory
      .npm

      # Optional eslint cache
      .eslintcache

      # Optional REPL history
      .node_repl_history

      # Output of 'npm pack'
      *.tgz

      # Yarn Integrity file
      .yarn-integrity

      # dotenv environment constiables file
      .env


      # End of https://www.gitignore.io/api/node

      # Created by https://www.gitignore.io/api/OSX

      ### OSX ###
      *.DS_Store
      .AppleDouble
      .LSOverride

      # Icon must end with two \r
      Icon


      # Thumbnails
      ._*

      # Files that might appear in the root of a volume
      .DocumentRevisions-V100
      .fseventsd
      .Spotlight-V100
      .TemporaryItems
      .Trashes
      .VolumeIcon.icns
      .com.apple.timemachine.donotpresent

      # Directories potentially created on remote AFP share
      .AppleDB
      .AppleDesktop
      Network Trash Folder
      Temporary Items
      .apdisk

      # End of https://www.gitignore.io/api/OSX

      `
    );
  },

  install: function () {
    this.installDependencies({
      bower: false,
      npm: false,
      yarn: true
    });
  },

  end: function () {
    this.log(chalk.green(
      '🍺 Everything is done!'
    ));
  }
});
